<?php

/**
 * @Author:      zwh
 * @DateTime:    2016-1-19 10:16:50
 * @Description: 用于门店的各种 维护 修改操作
 */
class ScsShopController extends BaseController
{   

    /**
     * @Author   lyt                      <ahlyt@anhuibj.com>
     * @DateTime 2017-11-02T15:37:13+0800
     * @return   [type]                   [description]
     * 用于门店的上传萨摩亚数据
     */
    public function createSMY(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                "date"=>"required", // 
                "data"=>"required", // 
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            try{
                Log::info(Input::get('data'));
                $data = json_decode(Input::get('data'),true);
                Log::info($data);
            }catch (Exception $e){
                $response = Lang::get("scs_error.maintenance_shop_date_error_70000");
                break;
            }
            $date=Input::get("date");
            $wrong = array();
            $wrong_not_exist = array();
            $response = DB::transaction(function () use ($date,$data,$sc_user) {
                SmyImport::where("created_date",$date)->where("shop_id",$sc_user->shop_id)->delete(); //清除导入当天的数据
                foreach($data as $key=>$v){
                    $time=date("Y-m-d",strtotime($v["Date/time"]));
                    $alltime=date("Y-m-d H:i:s",strtotime($v["Date/time"]));
                    if($time!=$date){
                        DB::rollBack();
                        $response=Lang::get("scs_error.maintenance_shop_date_error_70005");
                        $response['msg']=$response['msg'].' 请检查第'.$key."行";
                        return $response;
                    }
                    if(!is_numeric($v["Dispensed Qty"])||!is_numeric($v["Stock level"])){//如果日期不符或者数据格式错误
                        DB::rollBack();
                        $response=Lang::get("scs_error.maintenance_shop_date_error_70000");
                        $response['msg']=$response['msg'].' 请检查第'.$key."行,用量,剩余量";
                        return $response;
                    }       
                    $si=new SmyImport;
                    $si->shop_id=$sc_user->shop_id;     
                    $si->created_date=$date;      
                    $si->smy_date=$alltime;    
                    $si->smy_job=$v["JOB"];    
                    $si->smy_operator=$v["Operator"];         
                    $si->smy_product=$v["Product"];        
                    $si->smy_dispensed_qty=$v["Dispensed Qty"];         
                    $si->smy_stock_level=$v["Stock level"];     
                    $si->create_by=$sc_user->id;     
                    $si->save(); 
                }
                return array('code' => 0, 'msg' => 'ok', 'result' => array());
            });
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "createSMY", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    /**
     * @Author:      lyt
     * @DateTime:    2016-02-22 11:30:48
     * @Description: 用于 添加门店的耗材
     */
    /**
     * @Author:      lyt
     * @DateTime:    2016-04-29 11:48:07
     * @Description: 添加建议售价的必选
     *               商品编码必须 包装必选 添加条形码 字段
     */
    // public function createsupply(){
    // 	$validator = Validator::make(Input::all(),
    //         array(
    //             'token' => 'required',
    //             "subject"=>"required", // 字段废弃 5-5 字段启用
    //             "st_classifi_id"=>"required",      //统计分类的id
    //             "location"=>"required|max:100", //仓库的仓位
    //             'use_status'=>"required", //使用状态
    //             'car_model'=>'max:255', //使用状态
    //             // "outbound_amount"=>"required",// 出库基价
    //             "amount"=>"required",// 建议售价
    //             "code"=>"required|max:100",//编码 现在废弃适用规格字段
    //             "specification"=>"max:100",//规格
    //             // "name"=>"required|max:100",
    //             "model"=>"max:100",//型号
    //             "unit"=>"required|max:20",//售卖单位
    //             "pack_unit"=>"required|max:20", //包装数量
    //             // "retrieval_code"=>"required|max:100", //检索码 现在是  三级分类 加上 品牌系列型号  车型 拼接字段
    //             "brand_name"=>"required|max:100",//品牌
    //             "series_name"=>"max:100",//系列
    //             "ids"=>"required",//车型
    //             "old_code"=>"max:100",//原商品编码
    //             "new_subject_name"=>"max:100",//原商品编码
    //             "bar_code"=>"max:100",//条形码
    //             "bz_unit"=>"required|max:20",//标准单位
    //         )
    //     );
    //     $response = array('code' => 0, 'msg' => 'ok');
    // 	do{
    // 		if($validator->fails()) {
    //             $response = Lang::get("scs_error.args_error_10000");
    //             $response["result"]=$validator->messages()->all();
    //             break;
    //         }
    //         $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
    //         if(is_null($sc_user)){
    //             break;
    //         }
    //         $sins=SupplyItemNonStandard::where("shop_id",$sc_user->shop_id)->where('code',Input::get('code'))->first();
    //         if($sins){
    //             $response = Lang::get("scs_error.supply_exit_error_10005");
    //             break;
    //         }
    //         $ids = json_decode(Input::get('ids'));

    //         // $scf=StatisticalClassification::find(Input::get("st_classifi_id"));
    //         $fenlei=StatisticalClassification::leftJoIn("statistical_classification as sc","sc.id","=","statistical_classification.parent_id")->
    //         leftJoIn("statistical_classification as sc2","sc2.id","=","sc.parent_id")->select("statistical_classification.retrieval_code","statistical_classification.name","sc.retrieval_code as two_rc","sc.name as two_name","sc2.retrieval_code as one_rc","sc2.name as one_name")->where("statistical_classification.id",Input::get("st_classifi_id"))->first(); 

    //         $sins=new SupplyItemNonStandard;
    //         $sins->name=Input::get("series_name").Input::get("model").Input::get("specification"); //现在等于 品牌 系列 型号相加
    //         $sins->location=Input::get("location");
    //         $sins->use_status=Input::get('use_status');
    //         $sins->car_model=Input::get('car_model');
    //         $sins->code=Input::get("code");
    //         $sins->subject=Input::get("subject");
    //         $sins->brand_name=Input::get("brand_name");
    //         $sins->series_name=Input::get("series_name");
    //         $sins->model=Input::get("model");
    //         $sins->shop_id=$sc_user->shop_id;
    //         $sins->outbound_amount=Input::get("outbound_amount")*100;
    //         $sins->claim_amount=Input::get("claim_amount")*100;
    //         $sins->insurance_amount=Input::get("insurance_amount")*100;
    //         $sins->unit=Input::get("unit");
    //         $sins->pack_unit=Input::get("pack_unit");
    //         $sins->retrieval_code=$fenlei->one_rc.$fenlei->two_rc.$fenlei->retrieval_code.$fenlei->one_name.$fenlei->two_name.$fenlei->name.
    //         Input::get("brand_name").Input::get("series_name").Input::get("model").Input::get("code").Input::get("specification").Input::get('old_code').Input::get('car_model');
    //         $sins->status=1;
    //         $sins->desc=Input::get("desc");
    //         $sins->amount=Input::get("amount")*100;
    //         $sins->st_classifi_id=Input::get("st_classifi_id");
    //         $sins->bz_unit=Input::get("bz_unit");
    //         $sins->specification=Input::get("specification");
    //         $sins->old_code=Input::get("old_code");
    //         $sins->new_subject_name=Input::get("new_subject_name");   
    //         $sins->bar_code=Input::get("bar_code");
    //         $sins->save();
            
    //         $sl=new SupplyLocation;
    //         $sl->item_id=$sins->id;
    //         $sl->item_type=1;
    //         $sl->shop_id=$sc_user->shop_id;
    //         $sl->location=Input::get('location');
    //         $sl->save();
    //         $response = array('code' => 0, 'msg' => 'ok', 'result' => array("id"=>$sins->id));
    // 	}while(false);
    // 	Log::info("info", array("system" => "scs" ,"event" => "createsupply", 'input' =>Input::all() ,"output" => $response));
    //     return json_encode($response);
    // }


    /**
     * @Author:      lyt
     * @DateTime:    2016-11-07 14:04:30
     * @Description: 更新耗材的货位
     */
    public function updatesupplyLocation(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'item_id'=> 'required',
                // "item_type"=>"required", //耗材类型
                "location"=>"required", //仓库的仓位
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            // if(Input::get("item_type")==0){
                $item_info=SupplyItem::find(Input::get('item_id'));
            // }else{
            //     $item_info=SupplyItemNonStandard::find(Input::get('item_id'));
            // }
            if(!$item_info){
                $response = Lang::get("scs_error.supply_item_not_exit_41000");
                break;
            }            
            
            $sl=SupplyLocation::where('item_id',Input::get('item_id'))->where('shop_id',$sc_user->shop_id)->first();
            if($sl){
                $sl->item_type=$item_info->type;
                $sl->location=Input::get("location");
                $sl->save();
            }else{
                $sl=new SupplyLocation;
                $sl->item_id=Input::get('item_id');
                $sl->item_type=$item_info->type;
                $sl->shop_id=$sc_user->shop_id;
                $sl->location=Input::get("location");
                $sl->save();
            }
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("id"=>Input::get('item_id')));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "updatesupplyLocation", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-8-2 13:44:26
     * @Description: 修改配件
     *               
     */
    // public function updatesupply(){
    //     $validator = Validator::make(Input::all(),
    //         array(
    //             'token' => 'required',
    //             'item_id'=> 'required',
    //             //"subject"=>"required", // 字段废弃 5-5 字段启用
    //             //"st_classifi_id"=>"required",      //统计分类的id
    //             "location"=>"required|max:100", //仓库的仓位
    //             'use_status'=>"required", //使用状态
    //             'car_model'=>'max:255', //使用状态
    //             // "outbound_amount"=>"required",// 出库基价
    //             "amount"=>"required",// 建议售价
    //             //"code"=>"required|max:100",//编码 现在废弃适用规格字段
    //             "specification"=>"max:100",//规格
    //             // "name"=>"required|max:100",
    //             "model"=>"max:100",//型号
    //             "unit"=>"required|max:20",//售卖单位
    //             "pack_unit"=>"required|max:20", //包装数量
    //             // "retrieval_code"=>"required|max:100", //检索码 现在是  三级分类 加上 品牌系列型号  车型 拼接字段
    //             "brand_name"=>"required|max:100",//品牌
    //             "series_name"=>"max:100",//系列
    //             "ids"=>"required",//车型
    //             "old_code"=>"max:100",//原商品编码
    //             //"new_subject_name"=>"max:100",//原商品编码
    //             "bar_code"=>"max:100",//条形码
    //             "bz_unit"=>"required|max:20",//标准单位
    //         )
    //     );
    //     $response = array('code' => 0, 'msg' => 'ok');
    //     do{
    //         if($validator->fails()) {
    //             $response = Lang::get("scs_error.args_error_10000");
    //             $response["result"]=$validator->messages()->all();
    //             break;
    //         }
    //         $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
    //         if(is_null($sc_user)){
    //             break;
    //         }
    //         $item_id=Input::get('item_id');
    //         $sins=SupplyItemNonStandard::find(Input::get('item_id'));
    //         if($sc_user->shop_id !=$sins->shop_id){
    //             $response = Lang::get("scs_error.supply_item_source_error_41006");
    //             break;
    //         }
    //         $_sins=SupplyItemNonStandard::where("shop_id",$sc_user->shop_id)->where('id','!=',Input::get('item_id'))->where('code',Input::get('code'))->first();
    //         if($_sins){
    //             $response = Lang::get("scs_error.supply_exit_error_10005");
    //             break;
    //         }
    //         $fenlei=StatisticalClassification::leftJoIn("statistical_classification as sc","sc.id","=","statistical_classification.parent_id")
    //             ->leftJoIn("statistical_classification as sc2","sc2.id","=","sc.parent_id")
    //             ->select("statistical_classification.retrieval_code","statistical_classification.name","sc.retrieval_code as two_rc","sc.name as two_name","sc2.retrieval_code as one_rc","sc2.name as one_name")
    //             ->where("statistical_classification.id",$sins->st_classifi_id)
    //             ->first();
    //         $sins->name=Input::get("series_name").Input::get("model").Input::get("specification"); //现在等于 品牌 系列 型号相加
    //         $sins->location=Input::get("location");
    //         $sins->use_status=Input::get('use_status');
    //         $sins->car_model=Input::get('car_model');
    //         //$sins->code=Input::get("code");
    //         //$sins->subject=Input::get("subject");
    //         $sins->brand_name=Input::get("brand_name");
    //         $sins->series_name=Input::get("series_name");
    //         $sins->model=Input::get("model");
    //         $sins->shop_id=$sc_user->shop_id;
    //         $sins->outbound_amount=Input::get("outbound_amount")*100;
    //         $sins->claim_amount=Input::get("claim_amount")*100;
    //         $sins->insurance_amount=Input::get("insurance_amount")*100;
    //         $sins->unit=Input::get("unit");
    //         $sins->pack_unit=Input::get("pack_unit");
    //         $sins->bz_unit=Input::get("bz_unit");
    //         $sins->status=1;
    //         $sins->desc=Input::get("desc");
    //         $sins->amount=Input::get("amount")*100;
    //         //$sins->st_classifi_id=Input::get("st_classifi_id");
    //         $sins->specification=Input::get("specification");
    //         $sins->old_code=Input::get("old_code");
    //         $sins->bar_code=Input::get("bar_code");
    //         //$sins->new_subject_name=Input::get("new_subject_name");
    //         $sins->retrieval_code=$fenlei->one_rc.$fenlei->two_rc.$fenlei->retrieval_code.$fenlei->one_name.$fenlei->two_name.$fenlei->name.
    //         $sins->brand_name.$sins->series_name.$sins->model.$sins->code.$sins->specification.$sins->old_code.$sins->car_model;
    //         $sins->save();
            
    //         $sl=SupplyLocation::where('item_id',Input::get('item_id'))->where('shop_id',$sc_user->shop_id)->where('item_type',1)->first();
    //         if($sl){
    //             $sl->location=Input::get("location");
    //             $sl->save();
    //         }else{
    //             $sl=new SupplyLocation;
    //             $sl->item_id=$sins->id;
    //             $sl->item_type=1;
    //             $sl->shop_id=$sc_user->shop_id;
    //             $sl->location=Input::get("location");
    //             $sl->save();
    //         }
    //         if($sins->use_status==0){
    //             MaintenanceWarehouseWarn::where('item_id',Input::get('item_id'))->where('item_type',1)->update(array('status'=>0));
    //         }
    //         Cache::forget('supply_non_item_'.$item_id);
    //         $response = array('code' => 0, 'msg' => 'ok', 'result' => array("id"=>$sins->id));
    //     }while(false);
    //     Log::info("info", array("system" => "scs" ,"event" => "updatesupply", 'input' =>Input::all() ,"output" => $response));
    //     return json_encode($response);
    // }
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-8-2 13:44:26
     * @Description: 配件详情
     *
     */
    // public function supplydetail(){
    //     $validator = Validator::make(Input::all(),
    //         array(
    //             'token' => 'required',
    //             'item_id'=> 'required',
    //         )
    //     );
    //     $response = array('code' => 0, 'msg' => 'ok');
    //     do{
    //         if($validator->fails()) {
    //             $response = Lang::get("scs_error.args_error_10000");
    //             $response["result"]=$validator->messages()->all();
    //             break;
    //         }
    //         $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
    //         if(is_null($sc_user)){
    //             break;
    //         }
    //         $sins=SupplyItemNonStandard::find(Input::get('item_id'));
    //         $ss=SupplySubject::find($sins->subject);
    //         $sl=SupplyLocation::where('item_id',Input::get('item_id'))->where('shop_id',$sc_user->shop_id)->where('item_type',1)->first();
    //         $sins->location=isset($sl->location) ? $sl->location : "";
    //         $sins->subject_name=$ss->name;
    //         $fenlei=StatisticalClassification::leftJoIn("statistical_classification as sc","sc.id","=","statistical_classification.parent_id")
    //         ->leftJoIn("statistical_classification as sc2","sc2.id","=","sc.parent_id")
    //         ->select("statistical_classification.name","sc.name as two_name","sc2.name as one_name")
    //         ->where("statistical_classification.id",$sins->st_classifi_id)->first();
    //         $sins->two=$fenlei->two_name;
    //         $sins->three=$fenlei->name;
    //         if($sc_user->shop_id !=$sins->shop_id){
    //             $response = Lang::get("scs_error.supply_item_source_error_41006");
    //             break;
    //         }
    //         $response = array('code' => 0, 'msg' => 'ok', 'result' => array("sins"=>$sins));
    //     }while(false);
    //     Log::info("info", array("system" => "scs" ,"event" => "updatesupply", 'input' =>Input::all() ,"output" => $response));
    //     return json_encode($response);
    // }
    
    /**
     * @Author:      lyt
     * @DateTime:    2016-02-24 16:28:57
     * @Description: 用于添加供应商的借口
     */
    /**
     * @Author   lyt                      <ahlyt@anhuibj.com>
     * @DateTime 2017-12-06T13:49:33+0800
     * @return   [type]                   [description]
     * 修改 供应商 s22
     */
    public function createSupplier(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',                
                "bm"=>"required|max:100",
                "name"=>"required|max:100",
                // "status"=>"required|in:0,1",
                "contacts"=>"required|max:100", 
                "contacts_number"=>"required|max:100",     
                // "contacts_phone"=>"max:100", 
                // "address"=>"max:100", 
                // "postcode"=>"max:100", 
                // "fax"=>"max:100",       
                // "bank"=>"max:200", 
                // "account"=>"max:200", 
                // "major_type"=>"required",     //主营类型 1-车型，2-品牌，为空则未设置
                "other_info"=>"max:100",      //其他信息
                "car_type"=>"max:200",        //主营业务               
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            // $temp_ms=MaintenanceSupplier::where("shop_id",$sc_user->shop_id)->where("bm",Input::get("bm"))->first();
            // if($temp_ms){//如果存在 则说明 编码重复了
            //     $response = Lang::get("scs_error.supplier_code_error_10003");
            //     break;
            // }
            $temp=MaintenanceSupplier::where("name",strtoupper(Input::get("name")))->count();
            if($temp>0){
                $response = Lang::get("scs_error.supplier_error_10014");
                break;
            }
            $temp=MaintenanceSupplier::where("contacts_number",Input::get("contacts_number"))->count();
            if($temp>0){
                $response = Lang::get("scs_error.supplier_error_10015");
                break;
            } 

            $kingdee_supper=0;
            // $url = Config::get('config.kingdee_local_api').'/kingdeescs/create_suppller?token='.sha1(md5('anhuiscs'.date("Y-m-d H",time()))).'&name='.Input::get("name");
            // $re = Httpful::get($url)
            //     ->timeoutIn(150)
            //     ->sendsForm()->send();
            // $re = json_decode($re->body);
            // if($re->code!=0){
            //     Log::error($re->msg);
            //     $response = Lang::get("scs_error.supplier_error_10015");
            //     break;
            // } 
            
            $ms=new MaintenanceSupplier;
            $ms->shop_id=$sc_user->shop_id;
            $ms->created_type=4;
            $ms->create_by=$sc_user->id;
            $ms->bm=Input::get("bm");
            $ms->name=strtoupper(Input::get("name"));            
            $ms->contacts=Input::get("contacts");
            $ms->contacts_number=Input::get("contacts_number");
            // $ms->contacts_phone=Input::get("contacts_phone");
            // $ms->address=Input::get("address");
            // $ms->postcode=Input::get("postcode");
            // $ms->fax=Input::get("fax");
            $ms->type=1;
            $ms->kingdee_supper=0;
            // $ms->bank=Input::get("bank");
            // $ms->account=Input::get("account");
            // $ms->duty=Input::get("duty");
            // 
            if(Input::get("major_type")){
                $ms->major_type=Input::get("major_type");
            }            
            $ms->other_info=Input::get("other_info");
            $ms->car_type=Input::get("car_type");
            $ms->purchase_type=2;
            $ms->status=1;
            $ms->save();
            
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("id"=>$ms->id));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "createSupplier", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }  

    /**
     * @Author:      lyt
     * @DateTime:  2017-06-06 10:42:09
     * @Description: 用于添加 修改供应商的接口
     */
    public function updateSupplier(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',      
                "id"=>"required",          
                // "bm"=>"required|max:100",
                // "name"=>"required|max:100",
                // "status"=>"required|in:0,1",
                // "type"=>"required|in:2,1",
                "contacts"=>"max:100", 
                "contacts_number"=>"max:100",     
                // "contacts_phone"=>"max:100", 
                // "address"=>"max:100", 
                // "postcode"=>"max:100", 
                // "fax"=>"max:100",     
                // "bank"=>"max:200", 
                // "account"=>"max:200", 
                // "duty"=>"max:200", 
                // "major_type"=>"required",     //主营类型 1-车型，2-品牌，为空则未设置
                "other_info"=>"max:100",      //其他信息
                "car_type"=>"max:200",        //主营业务        
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $ms=MaintenanceSupplier::where("id",Input::get("id"))->where("purchase_type",2)->first();
            if(is_null($ms)){
                $response = Lang::get("scs_error.supplier_error_10013");
                break;
            }
            // $temp_ms=MaintenanceSupplier::where("shop_id",$sc_user->shop_id)->where("bm",Input::get("bm"))->where("id","!=",Input::get("id"))->first();
            // if($temp_ms){//如果存在 则说明 编码重复了
            //     $response = Lang::get("scs_error.supplier_code_error_10003");
            //     break;
            // }
            // $ms=new MaintenanceSupplier;
            // $ms->shop_id=$sc_user->shop_id;
            // $ms->create_by=$sc_user->id;
            // $ms->bm=Input::get("bm");
            // $ms->name=strtoupper(Input::get("name"));            
            $ms->contacts=Input::get("contacts");
            $ms->contacts_number=Input::get("contacts_number");
            // $ms->contacts_phone=Input::get("contacts_phone");
            // $ms->address=Input::get("address");
            // $ms->postcode=Input::get("postcode");
            // $ms->fax=Input::get("fax");
            // $ms->type=Input::get("type");            
            // $ms->bank=Input::get("bank");
            // $ms->account=Input::get("account");
            // $ms->duty=Input::get("duty");
            if(Input::get("major_type")){
                $ms->major_type=Input::get("major_type");
            }            
            $ms->other_info=Input::get("other_info");
            $ms->car_type=Input::get("car_type");
            // $ms->status=Input::get("status")==1?1:0;
            $ms->save();
            $msg="";
            $temp=MaintenanceSupplier::where("contacts_number",Input::get("contacts_number"))->count();
            if($temp>1){
               $msg=$msg."，供货商电话存在重复";
            }
            $msg=strlen($msg)>0?'提示'.$msg:$msg;
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("id"=>$ms->id,"msg"=>$msg));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "updateSupplier", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }  
    
    
    public function inquire()
    {
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            // $ppc=ProductPackageCity::where("city_id",$sc_user->shop->city_id)->where("status",1)->select("pack_id")->get()->toArray();
            $ppc=ProductPackageShop::getShopPackage($sc_user->shop_id);
            $classifi = DB::table('product_classification')->get();
            foreach ($classifi as $v) {
                $v->packages = ProductPackage::whereIn("id",$ppc)->where('status', 1)
                ->where('place', 2)
                ->where('classification',$v->id)
                ->select(array('id', 'name', 'desc'))
                ->orderBy('sort', 'asc')
                ->get()->toArray();
            }

            $response = array('code' => 0, 'msg' => 'ok','result'=>array('classifi'=>$classifi));
        }while(false);
        // Log::info("info", array("system" => "scs" ,"event" => "createSupplier", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    

    /**
     * @Author:      zwh
     * @DateTime:    2016-8-1 17:26:44
     * @Description: 询价
     */
    public function inresult(){
        
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                "packages"=>"required",
                "car_model_id"=>"required",
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $pack_arr = json_decode(Input::get('packages'),1);
            $city = $sc_user->shop->city_id;
            $place = 2;
            $csi = DataCarStandardInfo::find(Input::get('car_model_id')); //车型
            $work_model_coe = WorkModelCoefficient::where('name',$csi->model_level)->select('work_coefficient')->first(); //车型的价格系数
            $work_coefficient = isset($work_model_coe->work_coefficient) ? $work_model_coe->work_coefficient : 1; //人工价格系数
            $whp=WorkHoursPrice::where("city_id",$sc_user->shop->city_id)->first();
            $work_price = isset($whp->price) ? $whp->price : 1; //人工价格
            
            // $csi=DataCarModel::find($orders->car_model_id); 
            // $tuijian=SupplyRecommend::getRecommendByCarModel($csi);
            //人工费
            $check_service = Service::getServiceByPackIds($pack_arr, $place);
            $check_service_ids = array();
            foreach ($check_service as $key => $value) {
                $check_service_ids[$value['pack_id']][] = $value;
            }
            $item_info_arr = array();
            foreach($check_service_ids as $key1=>$vl){
                $item_info = array();
                $item_info = DataSupplyProductItem::leftjoin('anhui.supply_item', 'supply_product_item.supply_item_id', '=', 'supply_item.erp_id')
                ->leftjoin('anhui_data.supply_brand', 'supply_brand.id', '=', 'supply_item.brand_id')
                ->leftjoin('anhui_data.supply_series', 'supply_series.id', '=', 'supply_item.series_id')
                // ->leftjoin('anhui_data.supply_subject', 'supply_subject.id', '=', 'supply_item.subject')
                ->leftjoin('anhui.product_pack_item', 'product_pack_item.item_id', '=', 'supply_item.supply_classification_id')
                ->leftJoin("anhui.supply_classification","supply_classification.id","=","supply_item.supply_classification_id")
                ->leftJoin("anhui_data.supply_unit as sale_unit","sale_unit.id","=","supply_item.sale_unit_id")
                // ->leftJoin(DB::raw("(select * from anhui.supply_sub where `status`=1) as supply_sub"), 'supply_sub.id',"=","supply_item.id")
                // ->where('supply_subject.status', 1)
                ->where('supply_item.type', 0)
                ->where('supply_item.status', 1)
                ->where('supply_brand.status', 1)
                //->where('supply_product_item.city', $city)
                ->where('supply_product_item.status', 1)
                ->where('supply_product_item.car_model_id', Input::get('car_model_id'))
                ->where('product_pack_item.pack_id', $key1)
                ->where('product_pack_item.status', 1)
                ->where('product_pack_item.type', 3)
                ->where('product_pack_item.status', 1)
                // ->where('supply_series.status', 1)
                ->select(array('supply_item.id','supply_item.brand_id','supply_item.name as item_name', 'supply_item.desc','supply_item.model', 'supply_brand.brand_name', 'supply_item.series_id',
                    'supply_series.name', 'product_pack_item.pack_id','supply_product_item.number','supply_product_item.max_number','supply_product_item.isdefualt',
                    'supply_item.supply_classification_id as subject', 'supply_item.desc as small_desc','sale_unit.name as unit',"supply_classification.name as scf_name"))
                ->orderBy('supply_product_item.isdefualt', 'desc')->orderBy('supply_product_item.id', 'desc')
                ->get()->toArray();
                if(count($item_info)>0){ //组合为统一结构(产品包中存在耗材)
                    foreach ($item_info as $key => $value) {
                        $wpc=WorkPartsCoefficient::where("car_model_name",$csi->model_level)->where("supply_brand_id",$value['brand_id'])->where("supply_subject_id",$value['subject'])->where("status",1)->first();
                        $supply_coefficient = null;
                        if (!empty($wpc)) {
                            $wpc_city=WorkPartsCoefficientCity::where('city_id',$sc_user->shop->city_id)->where('coefficient_id',$wpc->id)->where('status',1)->first();
                            $supply_coefficient=isset($wpc_city->coefficient) ? $wpc_city->coefficient : null; //如果有城市系数，优先使用。
                        }
                        if ($supply_coefficient == null){ //如果是null，说明没有赋值
                            $supply_coefficient=isset($wpc->coefficient) ? $wpc->coefficient : 1;
                        }
                        $value['recommend']=1;
                        $value['icon']="";
                        $value['specification']="";
                        // $value['number']=1;
                        // $value['max_number']=1;
                        // $value['isdefualt']=0;

                        $a[]=$wpc;
                        // if(in_array($value['id'], $tuijian)){
                        //     $value['isdefualt']=1;
                        // }
                        $dmcc=DataCarMaintenanceClassificationConfig::where("car_model_id",Input::get('car_model_id'))->where("supply_classification_id",$value['subject'])->where("status",1)->first();
                        // if(isset($dmcc)){
                        //     $value['number']=$dmcc->number;
                        //     $value['max_number']=$dmcc->number;
                        // }
                        // $sip=SupplyItemPrice::where("item_id",$value['id'])->where("city_id",$city)->first();
                        // if($sip){
                        //     $value['amount']=$sip->price;
                        // }
                        $sip=SupplyCityPrice::where("supply_id",$value['id'])->where("city_id",$sc_user->shop->city_id)->where("status",1)->first();
                        if($sip){
                            $value['amount']=$sip->price;
                        }else{
                            $ss_temp=SupplySub::where("supply_id",$value['id'])->where("status",1)->first();
                            $value['amount']=isset($ss_temp)?$ss_temp->usual_price:0;
                        }   

                        $temp_mw=MaintenanceWarehouse::where("shop_id",$sc_user->shop_id)->where("item_id",$value["id"])->first();
                        $value['date_number']=isset($temp_mw)?$temp_mw->number:0;
                        $value['amount'] = $value['amount'] * $supply_coefficient;
                        $value['amount'] =Common::upFow($value['amount']);

                        $item_info_arr[$value['pack_id']]['item_info'][] = $value;
                        if (isset($item_info_arr[$value['pack_id']]) && empty($item_info_arr[$value['pack_id']]['service']) && isset($check_service_ids[$value['pack_id']])) {
                            $item_info_arr[$value['pack_id']]['service'] = $check_service_ids[$value['pack_id']];
                            $tmp_amount = 0;
                            foreach($check_service_ids[$value['pack_id']] as $k => $v){
                                $res=PricingStrategy::getStringStrategy($csi->id,$check_service_ids[$value['pack_id']][$k]['id'],$sc_user->shop->city_id);
                                if($res['code']==0){
                                    $tmp_amount=$res['price'];
                                }else{
                                    if($check_service_ids[$value['pack_id']][$k]['s_type']==1){
                                        $tmp_amount = $check_service_ids[$value['pack_id']][$k]['work_hours'] * $work_price * $work_coefficient;
                                    }elseif($check_service_ids[$value['pack_id']][$k]['s_type']==2){
                                        $tmp_amount = $check_service_ids[$value['pack_id']][$k]['price'];
                                    }
                                }
                                $item_info_arr[$value['pack_id']]['service'][$k]['amount'] = $tmp_amount;
                            }
                        }
                    }
                }else{ //组合为统一结构(产品包中不存在耗材，只有工时服务)
                    $item_info_arr[$key1]['service'] = $check_service_ids[$key1];
                    $tmp_amount = 0;
                    foreach($check_service_ids[$key1] as $k => $v){
                        $res=PricingStrategy::getStringStrategy($csi->id,$check_service_ids[$key1][$k]['id'],$sc_user->shop->city_id);
                        if($res['code']==0){
                            $tmp_amount=$res['price'];
                        }else{
                            if($check_service_ids[$key1][$k]['s_type']==1){
                                $tmp_amount = $check_service_ids[$key1][$k]['work_hours'] * $work_price * $work_coefficient;
                            }elseif($check_service_ids[$key1][$k]['s_type']==2){
                                $tmp_amount = $check_service_ids[$key1][$k]['price'];
                            }
                        }
                        $item_info_arr[$key1]['service'][$k]['amount'] = $tmp_amount;
                    }
                } 
            }
            $packages = ProductPackage::where('status', 1)
            ->whereIn('id', $pack_arr)
            ->where('place', 2)
            //->where('city', $city)
            ->select(array('id', 'name', 'desc', 'icon', 'is_checked', 'small_icon'))
            ->orderBy('sort', 'asc')
            ->get();
            $packages_value = array();
            foreach($packages as $p){
                $packages_value[$p->id] = $p->name;
            }
            foreach($pack_arr as $key => $value){
                if(!array_key_exists($value,$item_info_arr)){
                    $item_info_arr[$value] = [];
                }
            }
            $pack=array();
            foreach($item_info_arr as $k=>$item_info){
                $item_info['id']=$k;
                $pp=ProductPackage::find($k);
                $item_info['name']=$pp->name;
                $pack[]=$item_info;
            }
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array('packages'=>$pack));
        }while(false);
        // Log::info("info", array("system" => "scs" ,"event" => "inresult", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-8-26 14:23:52
     * @Description: 分类详情
     */
    public function scfDetail(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'scf_id'=> 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $scd=StatisticalClassifyDesc::find(Input::get('scf_id'));
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("scd"=>$scd));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "scfDetail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-10-13 16:21:46
     * @Description: 当前门店店长信息
     *
     */
    public function shop_manager(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $users=SCUser::where('shop_id',$sc_user->shop_id)->where('status',1)->where('title',1)->select('id','real_name')->get();
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("shop_manager"=>$users));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "shop_manager", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    


   /**
    * @Author:      lyt
    * @DateTime:  2017-06-14 11:28:03
    * @Description: 门店pos设备维护
    */
    public function shop_pos(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $users=MaintenancePosDevice::where('shop_id',$sc_user->shop_id)->where('status',1)->select('id','device_no','device_name','is_default')->get();
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("shop_pos"=>$users));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "shop_pos", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    
    /**
     * @Author:      zwh
     * @DateTime:    2017-1-24 11:50:49
     * @Description: 询价中配件搜索
     */
    /**
     * @Author   lyt                      <ahlyt@anhuibj.com>
     * @DateTime 2017-11-13T10:30:55+0800
     * @param int $current_number 库存数量状态  [1:库存大于0;2:全部; 默认值为2]
     * @param int $number_sort 库存排序  [1:正序;2:倒序;]
     * @link http://api.anhui.com/v1/scs/shop/supply_search?token=efc85ce01d0e523e5d4507fac1beb4f6&car_model_id=5189&st_classifi_id=41
     * @return   添加查询 不过滤 耗材库存逻辑 ，去除$sql,$sql2中  and  mw.number>0 (需求 s20, 一、询价商品无库存展示 )
     */
    public function supply_search(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'car_model_id' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok','result'=>array('order_id'=>Input::get('order_id')));
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $page_size=Input::get("page_size",10);
            $page=Input::get("page",1);
            $car_model_id=Input::get("car_model_id");
            $csi = DataCarStandardInfo::find($car_model_id); //车型
            $type="";
            $search_retrieval_code=Input::get("retrieval_code");
            $car_str=Input::get("car_str");
            $current_number = Input::get('current_number', 2);  //库存数量状态  [1:库存大于0;2:全部; 默认值为2]
            $number_sort = Input::get('number_sort', 0);        //库存排序  [1:正序;2:倒序;]
            
            if($type||$search_retrieval_code||$car_str){
                $si_ids=SupplyItem::retrievalCode("",$type,$search_retrieval_code,$car_str);//获得标准的耗材id范围
            }
            //标准配件列表
            $sql="select si.id,si.type,mw.number,1 as  recommend,spi.isdefualt from supply_item as si
                Join anhui_data.supply_product_item spi on spi.supply_item_id=si.id
                Left Join (select item_type,item_id,shop_id,number from maintenance_warehouse where shop_id=".$sc_user->shop_id.") mw on mw.item_id=si.id
                where car_model_id=".$car_model_id."  and spi.status=1";
            $sql2="select si.id,si.type,mw.number,0 as  recommend,0 as isdefualt from supply_item as si
                Left Join (select item_type,item_id,shop_id,number from maintenance_warehouse where shop_id=".$sc_user->shop_id.") mw on mw.item_id=si.id
                where 1=1 ";
            if(Input::get("st_classifi_id")){
                $sql=$sql.' and si.supply_classification_id='.Input::get("st_classifi_id");
                $sql2=$sql2.' and si.supply_classification_id='.Input::get("st_classifi_id");
            }
            if(Input::get("code")){
                $sql=$sql.' and si.code like "%'.Input::get("code").'%"';
                $sql2=$sql2.' and si.code like "%'.Input::get("code").'%"';
            }
            if(Input::get('brand_name')){
                $sql.=" and si.brand_name like '%".Input::get('brand_name')."%'";
                $sql2.=" and si.brand_name like '%".Input::get('brand_name')."%'";
            }
            if($current_number == 1){
                $sql.=" and mw.number > 0";
                $sql2.=" and mw.number > 0";
            }
            if(isset($si_ids)){
                $si_ids[]=0;
                $sql.=" and si.id in (".implode(",",$si_ids).")";
            }
            $sql.=' order by recommend desc,isdefualt desc';
            // Log::info($sql);
            $arr=DB::select($sql." limit 1000");//查询 匹配的标准配件
            //标准配件分为推荐和所有标准配件
            $pipei_id=array();
    
            //所有配件中取出推荐配件（去重）
            foreach($arr as $key=>$a){
                $pipei_id[]=$a->id;
            }
            if(isset($si_ids)){
                $temp_ids=array_diff($si_ids, $pipei_id);
                $temp_ids[]=0;
                $sql2.=" and si.id in (".implode(",",$temp_ids).")";
            }else{
                if(sizeof($pipei_id) >= 1){
                    $sql2.=" and si.id not in(".implode(",",$pipei_id).")";
                }
            }
            // Log::info($sql2);
            $arr2=DB::select($sql2." limit 1000");//查询 所有的标准配件
            $temp1=array_merge($arr,$arr2);
            // $tuijian=SupplyRecommend::getRecommendByCarModel($csi);
            $finally=$recommend=$isdefualt=array();
            $number_sort_arr = [];      //库存排序数组
            foreach($temp1 as $t){
                $si=SupplyItem::getCacheItemInfo($t->id);

                $supply_coefficient = null;
                $wpc=WorkPartsCoefficient::where("car_model_name",$csi->model_level)->where("supply_brand_id",$si->brand_id)->where("supply_subject_id",$si->supply_classification_id)->where("status",1)->first();                
                if (!empty($wpc)) {
                    $wpc_city=WorkPartsCoefficientCity::where('city_id',$sc_user->shop->city_id)->where('coefficient_id',$wpc->id)->where('status',1)->first();
                    $supply_coefficient=isset($wpc_city->coefficient) ? $wpc_city->coefficient : null; //如果有城市系数，优先使用。
                }
                if ($supply_coefficient == null){ //如果是null，说明没有赋值
                    $supply_coefficient=isset($wpc->coefficient) ? $wpc->coefficient : 1;
                }
                $sip=SupplyItemPrice::where("item_id",$si->id)->where("city_id",$sc_user->shop->city_id)->first();
                $mw=MaintenanceWarehouse::where('item_id',$si->id)->where('shop_id',$sc_user->shop_id)->first();
                if($sip){
                    $si->amount=$sip->price;
                }
                //多城市定价
                $sip=SupplyCityPrice::where("supply_id",$si->id)->where("city_id",$sc_user->shop->city_id)->where("status",1)->first();
                if($sip){
                    $si->amount=$sip->price;
                }else{
                    $ss_temp=SupplySub::where("supply_id",$si->id)->where("status",1)->first();
                    $si->amount=isset($ss_temp)?$ss_temp->usual_price:0;
                }
                // if(in_array($si->id, $tuijian)){
                //     $t->isdefualt=1;
                // }

                $si->amount=$si->amount*$supply_coefficient;
                $si->amount=Common::upFow($si->amount);
                // $t->subject=$si->subject;
                // $t->code=$si->code;
                // $t->old_code=$si->old_code;
                // $t->s_name=$si->subject_name;
                // $t->model=$si->model;
                // $t->amount=$si->amount;
                // $t->brand_name=$si->brand_name;
                // $t->se_name=$si->series_name;
                // $t->scf_id=$si->st_classifi_id;
                // $t->scf_name=$si->scf_name;
                // $t->specification=$si->specification;
                // $t->unit=$si->unit;
                // $t->car_model_comments=$si->car_model_comments;


                $item_array=array(
                    "id"=>$t->id,
                    "item_type"=>$t->type,
                    "number"=>$t->number,
                    "recommend"=>$t->recommend,
                    "isdefualt"=>$t->isdefualt,
                    "subject"=>$si->subject,
                    "code"=>$si->code,
                    "old_code"=>$si->old_code,
                    "order_code"=>$si->old_code,
                    "s_name"=>$si->subject_name,
                    "model"=>$si->model,
                    "amount"=>$si->amount,
                    "brand_name"=>$si->brand_name,
                    "se_name"=>$si->series_name,
                    "scf_id"=>$si->st_classifi_id,
                    "scf_name"=>$si->scf_name,
                    "specification"=>$si->specification,
                    "unit"=>$si->unit,
                    "car_model_comments"=>$si->car_model_comments,
                    "item_name"=>$si->name,
                );
                $finally[]=$item_array;
                $recommend[]=$t->recommend;
                $isdefualt[]=$t->isdefualt;
                $number_sort_arr[] = $t->number;
            }
            
            //依据库存排序
            if($number_sort == 1){
                array_multisort($number_sort_arr, $finally);
            }elseif ($number_sort == 2) {
                array_multisort($number_sort_arr, SORT_DESC, $finally);
            }else{
                array_multisort($recommend, SORT_DESC, $isdefualt, SORT_DESC, $finally);
            }
            $count=count($finally);
            $finally=array_slice($finally, ($page-1)*$page_size, $page_size);
            $result=array('count'=>$count,'si'=>$finally);
            $response['result']=$result;
        }while(false);
        // Log::info("info", array("system" => "scs" ,"event" => "supply_search", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }



   /**
    * @Author:      lyt
    * @DateTime:  2017-06-22 14:49:41
    * @Description: 用于支付类型的
    */
    public function paytype_search(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'scene_id' => 'required',//场景ID
            )
        );
        $response = array('code' => 0, 'msg' => 'ok','result'=>array('order_id'=>Input::get('order_id')));
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $rs=DB::select("SELECT apt.key,apt.`name`,apt.way,apt.push_way,apst.is_default FROM `all_pay_scene_types` apst LEFT JOIN all_pay_types apt on apt.id=apst.type_id where apst.shop_id=? and apst.scene_id=? and apst.available=1 and apst.optional=1 and apst.selected=1 order by apst.is_default desc",array($sc_user->shop_id,Input::get("scene_id")));
            $response['result']=array("pay_info"=>$rs);
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "supply_search", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author   lyt                      <ahlyt@anhuibj.com>
     * @DateTime 2018-01-31T14:28:36+0800
     * @return   [type]                   [description]
     * 耗材查询的 根据耗材的转换列表
     */
    public function supply_storage_search(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'item_id' => 'required',//场景ID
            )
        );
        $response = array('code' => 0, 'msg' => 'ok','result'=>array('order_id'=>Input::get('order_id')));
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $ss=SupplyStorage::where("origin_id",Input::get("item_id"))->where("status",1)->select("data_id","num")->orderBy("id","desc")->get();
            $finally=array();
            foreach ($ss as &$_ss) {
                $storage_si_info=SupplyItem::getCacheItemInfo($_ss->data_id);
                $_ss->item_id=$storage_si_info->id;
                $_ss->item_type=$storage_si_info->type;
                $_ss->code=$storage_si_info->code;
                $_ss->old_code=$storage_si_info->old_code;
                $_ss->brand_name=$storage_si_info->brand_name;
                $_ss->series_name=$storage_si_info->series_name;
                $_ss->model=$storage_si_info->model;
                $_ss->specification=$storage_si_info->specification;
                $_ss->scf_id=$storage_si_info->st_classifi_id;
                $_ss->scf_name=$storage_si_info->scf_name;
                $_ss->unit=$storage_si_info->unit;
                $_ss->bz_unit=$storage_si_info->bz_unit;
                $_ss->volume_size=$storage_si_info->pack;
                $_ss->car_model='';
                $_ss->car_model_comments=$storage_si_info->car_model_comments;
                $_ss->item_name=$storage_si_info->name;
                $sl=SupplyLocation::where('item_id',$_ss->data_id)->where('shop_id',$sc_user->shop_id)->first();
                $_ss->location=isset($sl->location) ? $sl->location : "";
                $finally[]=$_ss;
            }
            $_ss=new \stdClass;
            $storage_si_info=SupplyItem::getCacheItemInfo(Input::get("item_id"));
            $_ss->data_id=Input::get("item_id");
            $_ss->num=1;
            $_ss->item_id=$storage_si_info->id;
            $_ss->item_type=$storage_si_info->type;
            $_ss->code=$storage_si_info->code;
            $_ss->old_code=$storage_si_info->old_code;
            $_ss->brand_name=$storage_si_info->brand_name;
            $_ss->series_name=$storage_si_info->series_name;
            $_ss->model=$storage_si_info->model;
            $_ss->specification=$storage_si_info->specification;
            $_ss->scf_id=$storage_si_info->st_classifi_id;
            $_ss->scf_name=$storage_si_info->scf_name;
            $_ss->unit=$storage_si_info->unit;
            $_ss->bz_unit=$storage_si_info->bz_unit;
            $_ss->volume_size=$storage_si_info->pack;
            $_ss->car_model='';
            $_ss->car_model_comments=$storage_si_info->car_model_comments;
            $_ss->item_name=$storage_si_info->name;
            $sl=SupplyLocation::where('item_id',$_ss->data_id)->where('shop_id',$sc_user->shop_id)->first();
            $_ss->location=isset($sl->location) ? $sl->location : "";
            $finally[]=$_ss;

            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("count"=>sizeof($finally),"item_info"=>$finally));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "supply_storage_search", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
}